﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessObjects;

namespace UI
{
    public partial class frmQuanHuyen_Edit : FormBase
    {
        public frmQuanHuyen_Edit()
        {
            InitializeComponent();
        }
        public QuanHuyen ItemEdit { get; set; }
        public int? TinhThanhID { get; set; }

        private void frmQuanHuyen_Edit_Load(object sender, EventArgs e)
        {
            try
            {
                txtTenQuanHuyen.DataBindings.Add(new Binding("Text", ItemEdit, "TenQuanHuyen"));
                cboTinhThanh.DataBindings.Add(new Binding("EditValue", this, "TinhThanhID", true));
                //if (TinhThanhID == null)
                //    cboTinhThanh.ItemIndex = 0;
            }
            catch (Exception ex)
            {
                CommonError(ex);
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckInput())
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                CommonError(ex);
            }
            
        }

        private bool CheckInput()
        {
            bool result = true;
            dxErrorProvider1.ClearErrors();
            if (txtTenQuanHuyen.Text == string.Empty)
            {
                dxErrorProvider1.SetError(txtTenQuanHuyen, "Vui lòng nhập vào tên quận huyện!");
                result = false;
            }
            if (TinhThanhID == null)
            {
                dxErrorProvider1.SetError(cboTinhThanh, "Bạn chưa chọn tỉnh thành!");
                result = false;
            }
            return result;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
